package com.sanji.sjmallmodule.account;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.ImageView;
import android.widget.TextView;

import com.sanji.sjmallapp.R;

import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by fhm on 2017/1/14.
 */

public class SaleAfterAdapter extends BaseAdapter {
    private List<SaleAfterBean> mData;
    private Context mContex;

    public SaleAfterAdapter(List<SaleAfterBean> mData, Context mContex) {
        this.mData = mData;
        this.mContex = mContex;
    }

    public void notifyAdapter(List<SaleAfterBean> mData) {
        this.mData = mData;
        notifyDataSetChanged();
    }

    @Override
    public int getCount() {
        return mData.size();
    }

    @Override
    public Object getItem(int i) {
        return mData.get(i);
    }

    @Override
    public long getItemId(int i) {
        return i;
    }

    @Override
    public View getView(int i, View view, ViewGroup viewGroup) {
        ViewHolder vHolder = null;
        if (view == null) {
            view = LayoutInflater.from(mContex).inflate(R.layout.adapter_custom_after_item, null);
            vHolder = new ViewHolder(view);
            view.setTag(vHolder);
        } else {
            vHolder = (ViewHolder) view.getTag();
        }
        //捆绑数据
        SaleAfterBean bean = mData.get(i);
        vHolder.orderNumber.setText(bean.getOrderNumber());
        vHolder.customAfterTime.setText(bean.getOrderLaunchTime());
        vHolder.customAfterNumber.setText(bean.getCustomAfterNumber());
        vHolder.customAfterType.setText(bean.getOrderType());
        vHolder.serialNumber.setText(bean.getSerialNumber());
        vHolder.customAfterPrice.setText(bean.getOrderPrice());
        if (bean.getDealState() == 0) {
            vHolder.dealResultImg.setImageResource(R.mipmap.sale_after_dealing);
        } else if (bean.getDealState() == 1) {
            vHolder.dealResultImg.setImageResource(R.mipmap.sale_after_no_deal);
        } else if (bean.getDealState() == 2) {
            vHolder.dealResultImg.setImageResource(R.mipmap.sale_after_refuse_deal);
        }
        return view;
    }

    static class ViewHolder {
        @BindView(R.id.adapter_deal_result_img)
        ImageView dealResultImg;//处理进度
        @BindView(R.id.adapter_custom_after_time)
        TextView customAfterTime;//时间
        @BindView(R.id.adapter_order_number)
        TextView orderNumber;//订单号
        @BindView(R.id.adapter_custom_after_number)
        TextView customAfterNumber;//售后单号
        @BindView(R.id.adapter_custom_after_type)
        TextView customAfterType;//类型
        @BindView(R.id.adapter_serial_number)
        TextView serialNumber;//串码
        @BindView(R.id.adapter_custom_after_price)
        TextView customAfterPrice;//价格

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
